package com.zhiwei.configuration;

import com.zhiwei.vo.SysResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

//全局异常的处理，返回值为json
@Slf4j
@RestControllerAdvice
public class MyExceptionConfig {
    @ExceptionHandler({RuntimeException.class, SQLException.class, HttpMessageNotWritableException.class})
    public Object Handler(Exception e) {
//        将报错信息控制台打印
        log.error("服务异常", e);
        return SysResult.fail(e.getMessage());
    }
}

